package com.yangyu.controller;

import com.yangyu.message.BaseRsp;
import com.yangyu.message.user.RegisterVo;
import com.yangyu.pojo.User;
import com.yangyu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;

    @ApiOperation("获取全部用户")
    @GetMapping("/getUserInfo")
    public BaseRsp getUsers(HttpServletResponse response) {
        return service.getUserInfo(response);
    }

    @ApiOperation("获取全部用户")
    @PostMapping("/getUsers")
    public BaseRsp getUsers(@RequestBody User user) {
        return service.getUsers(user);
    }

    @ApiOperation("根据id获取用户")
    @PostMapping("/getUserById")
    public BaseRsp getUserById(@RequestBody User user) {
        return service.getUserById(user);
    }

    @ApiOperation("编辑用户")
    @PostMapping("/editUser")
    public BaseRsp editUser(@RequestBody User user) {
        return service.editUser(user);
    }

    @ApiOperation("添加用户")
    @PostMapping("/addUser")
    public BaseRsp addUser(@Validated @RequestBody RegisterVo user) {
        return service.addUser(user);
    }

    @ApiOperation("删除用户")
    @PostMapping("/deleteUser")
    public BaseRsp deleteUser(@RequestBody User user) {
        return service.deleteUser(user);
    }
}
